package com.ruijie.autotest.log.validation.paibo.tcp8848;

import com.minelx.landisk.filesystem.Paths;
import com.ruijie.autotest.log.common.crypto.Base64CryptoFactory;
import com.ruijie.autotest.log.common.crypto.CBC;
import com.ruijie.autotest.log.common.crypto.DESAlgorithm;
import com.ruijie.autotest.log.common.crypto.Padding;
import com.ruijie.autotest.log.common.socket.TCPPortTableFactory;
import com.ruijie.autotest.log.impl.data.SimpleTable;
import com.ruijie.autotest.log.impl.parse.*;
import com.ruijie.autotest.log.validation.hangzhouxiruan.ColumnVerification;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@SpringBootApplication
@PropertySources({
		@PropertySource("classpath:/mappings/paibo/application.properties")
})
public class TCP8848Test {

	private static final Logger logger = LoggerFactory.getLogger(TCP8848Test.class);

	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext validators = SpringApplication.run(TCP8848Test.class);

		SimpleTable.Builder tableBuilder = new SimpleTable.Builder(new GridColumnsParser(" ", 0).parseColumns(
				Paths.of("/C:/Users/123/ZYH_HOME/Projects/IdeaProjects/NetSupervisor/src/test/resources/mappings/paibo/columns.txt")
		));

		TCPPortTableFactory tableFactory = new TCPPortTableFactory(8848,
				tableBuilder,
				new ReduceEndCellsParser("\u0001"),
				Base64CryptoFactory.get().before(CBC.create(new DESAlgorithm(), "12345678", "12345678", Padding.PKCS_5_PADDING).cryptoFactory()).decryption()
		);

		tableFactory.start();

		logger.info(() -> "start sleeping.");

		Thread.sleep(50000);

		tableFactory.stop();

		ColumnVerification verification = new ColumnVerification(validators, tableFactory.createTable());
		verification.verify();

		System.out.println("we done.");
	}
}
